package com.mx.app.flatlaf;

import com.formdev.flatlaf.FlatLightLaf;
import com.mx.app.flatlaf.util.TableUtil;

import javax.swing.*;
import java.awt.*;

/**
 * 开源跨平台Swing外观样式库
 * 官网：https://www.formdev.com/flatlaf/#demo
 */
public class FlatlafDemo {
    public static void showPage() {
        // Set FlatLaf theme
        try {
            UIManager.setLookAndFeel(new FlatLightLaf());
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        SwingUtilities.invokeLater(() -> {
            JFrame frame = new JFrame("数据表格");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800, 600);

            // Layout
            frame.setLayout(new BorderLayout());

            JTable table = TableUtil.addTable(frame);
            // Button panel
            JPanel buttonPanel = new JPanel();
            JButton detailsButton = new JButton("查看详情");
            JButton exportButton = new JButton("导出数据");
            buttonPanel.add(detailsButton);
            buttonPanel.add(exportButton);

            frame.add(buttonPanel, BorderLayout.SOUTH);

            // Add action listener for "查看详情"
            detailsButton.addActionListener(e -> TableUtil.showDetails(table));

            // Add action listener for "导出数据"
            exportButton.addActionListener(e -> TableUtil.exportDataToExcel(table));

            // Show the frame
            frame.setVisible(true);
        });
    }


}
